#include<bits/stdc++.h>
#define fi first
#define se second
#define PII pair<int,int>
using namespace std;
const int N=2e5+10;
int lst[N],sum_[N];

int n,ans;

void dfs(int now,int r,int b,int sum)
{
    if(now>n)
    {
        ans=max(ans,sum);
        return;
    }
    if(sum_[n]-sum_[now-1]+sum<ans) return;
    int k=0;
    if(lst[now]==lst[r]) k=lst[r];
    dfs(now+1,now,b,sum+k);

    k=0;
    if(lst[now]==lst[b]) k=lst[b];
    dfs(now+1,r,now,sum+k);

}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int kase;
    cin>>kase;
    while(kase--)
    {
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>lst[i];
            sum_[i]=sum_[i-1]+lst[i];
        }
        lst[0]=-1;
        ans=0;
        dfs(2,1,0,0);
        cout<<ans<<"\n";
    }
}
